﻿using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using NH.Business.Implementations;
using NH.Business.Interfaces;
using NH.Web.AjaxServices.Contracts;

namespace NH.Web.AjaxServices
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(Name = "DoctorsService", Namespace = "")]
    public class DoctorsService
    {
        private readonly IDoctorBusiness _doctorBusiness;

        public DoctorsService()
        {
            _doctorBusiness = new DoctorBusiness();
        }

        [OperationContract]
        public DoctorsContract GetDoctors(int department = 0)
        {
            var results = new DoctorsContract();
            var listOfDoctors = _doctorBusiness.GetDoctors(department > 0 ? department : (int?)null);

            results.Doctors = listOfDoctors.Select(doctor => new KeyValueContract
                                                                 {
                                                                     Key = doctor.Id.ToString(),
                                                                     Value = doctor.FullName
                                                                 }).ToArray();

            
            return results;
        }
    }

    //[ServiceContract(Namespace = "")]
    //[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    //[ServiceBehavior(Name = "Doctors", Namespace = "")]
    //public class Doctors : IDoctorsService
    //{
    //    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
    //    // To create an operation that returns XML,
    //    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    //    //     and include the following line in the operation body:
    //    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    //    //[WebGet]
    //    //[OperationContract]
    //    public DoctorsContract GetDoctors(int department = 0)
    //    {
    //        var results = new DoctorsContract();

    //        var doctorBusiness = new DoctorBusiness();
    //        var listOfDoctors = doctorBusiness.GetDoctors(department > 0 ? department : (int?)null);

    //        results.Doctors = listOfDoctors.Select(doctor => new KeyValueContract
    //                                                             {
    //                                                                 Key = doctor.Id.ToString(), Value = doctor.FullName
    //                                                             }).ToArray();
    //        return results;
    //    }


    //    private readonly IDoctorsService _service;

    //    public Doctors()
    //    {
    //        _service = new TravelAgenciesService(ServiceFactory.Create<ITravelAgencyRepository>());
    //    }

    //    public TravelAgenciesContract GetTravelAgencies(string prefixText)
    //    {
    //        return _service.GetTravelAgencies(prefixText);
    //    }
    //}
}
